package cn.q3c.parse.stock2.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import cn.keyvalue.ccf.common.util.ObjectUtils;
import cn.q3c.parse.base.BaseProcess;
import cn.q3c.parse.stock2.object.StockInfo;

/**
 * 股票DBF处理类
 * @author wangxinning
 *
 */
public class Stock2DBFProcessImpl implements BaseProcess{

	private static final Logger logger = Logger.getLogger(Stock2DBFProcessImpl.class);

	public boolean process(Object obj) {
				
		@SuppressWarnings("unchecked")
		List<StockInfo> stockList = (List<StockInfo>)obj;
		
		// 处理日志列表（一只股票一天的交易数据）
		if (!ObjectUtils.isEmptyList(stockList)) {
			
			for( StockInfo stockInfo:stockList )
			{
				if ((StringUtils.equals(stockInfo.getExchange(), "sh") && StringUtils
						.startsWith(stockInfo.getCode(), "60"))
						|| (StringUtils.equals(stockInfo.getExchange(), "sz") && StringUtils
								.startsWith(stockInfo.getCode(), "00"))
						|| (StringUtils.equals(stockInfo.getExchange(), "sz") && StringUtils
								.startsWith(stockInfo.getCode(), "30")))
				{				
					try
					{
						Stock2ParseImpl.stockService.addStockInfo(stockInfo);
					}
					catch( Exception e )
					{
						logger.error("股票基础数据写入异常", e);
					}				
				}
			}
		}
		
		logger.debug("DBF更新成功");

		return true;
	}
}
